var allresizers = new Array();
function updateAllResizers()
{
	allresizers.each(function(r){r.updateOffset()});
}

var ResizerW = Class.create({
	element:null,
	width:null, 
	height:null,
	thick:6,
	offset:{x:null, y:null},
	padding:null,

	initialize: function(e)
	{
		allresizers.push(this);
		this.element = e = $(e);
		this.padding = parseInt(e.getStyle('padding-left')) + parseInt(e.getStyle('padding-right'));
		this.updateOffset();
		new Draggable(this.div, {
			constraint:"horizontal", 
			starteffect:null, 
			endeffect:null,
			onDrag:this.resize,
			onEnd:this.endResize
		});
	},
	
	updateOffset:function()
	{
		var dim = this.element.getDimensions();
		var offset = this.element.cumulativeOffset();
		this.height = dim.height;
		this.offset.x = offset[0]+dim.width - this.thick/2;
		this.offset.y = offset[1];
		this.updateDiv();
	},
	
	resize:function(div, event)
	{
		try
		{
			var t = div.element.model;
			var e = t.element;
			var eoffset = e.cumulativeOffset();
			var doffset = div.element.cumulativeOffset();
			var width = doffset[0] - eoffset[0] + t.thick/2 - t.padding;
			t.offset.x = doffset[0];
			e.setStyle({width:width+'px'});
			updateAllResizers();
		} 
		catch(ex){}
	},
	
	endResize:function(div, event)
	{
		var t = div.element.model;
		t.resize(div, event);
		if (typeof(t.afterResize)=='function')
			t.afterResize();
	},
	
	updateDiv: function()
	{
		if (!this.div)
		{
			this.div = new Element('div');
			this.div.addClassName('handler resize_w');
			this.div.model = this;
			$(document.body).insert(this.div);
		}
		return this.div.setStyle({
			width:this.thick+'px', 
			height:this.height+'px', 
			left:this.offset.x+'px',
			top:this.offset.y+'px'
		});
	}
});